package cn.sharp.bbs.dao.user;

import cn.sharp.bbs.entity.DO.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

public interface UserDao {
    int insertNewUser(User user);
    User selectUserByAccount(String account);
    @Select("select count(*) from t_comment where user_id=#{uid}")
    int getCommentNum(Long uid);

    @Select("select count(*) from t_collect_post where user_id=#{uid}")
    int getCollectNum(Long uid);

    @Select("select count(*) from t_follow_user where user_followed=#{uid}")
    int getFansNum(Long uid);

    @Select("select count(*) from t_follow_user where user_id=#{uid}")
    int getFollowNum(Long uid);

    int getLikeReceived(Long uid);

    @Select("select count(*) from t_post where user_id=#{uid}")
    int getPostNum(Long uid);

    User selectUserByMail(String mail);

    @Insert("insert into t_follow_user " +
            "(user_id, user_followed, fuser_time) " +
            "VALUE (#{source}, #{target}, now())")
    void followUser(Long source, Long target);

    @Select("select fuser_id from t_follow_user " +
            "where user_id=#{source} and user_followed=#{target}")
    Long getFollowId(Long source, Long target);

    @Delete("delete from t_follow_user where user_id=#{source} and user_followed=#{target}")
    void unfollowUser(Long source, Long target);

    @Select("select count(*) from t_follow_user where user_id=#{source} and user_followed=#{target}")
    int countFollowRelation(Long source, Long target);
}
